﻿namespace WebPacker.Tests.VersionGenerators
{
	using System;
	using NUnit.Framework;
	using WebPacker.Packs;
	using WebPacker.Packs.Resources;
	using WebPacker.VersionGenerators;

	[TestFixture]
	public abstract class VersionGeneratorBaseTest
	{
		[Test]
		public void SimpleGetNextVersionTest()
		{
			var generator = GetGenerator();
			var pack = GetTestPack();
			Assert.IsNotNull(generator.GetNextVersion(pack));
		}

		[Test]
		public void GetNextVersionForNullTest()
		{
			var generator = GetGenerator();
			Assert.Throws<ArgumentNullException>(() => generator.GetNextVersion(null));
		}

		protected abstract IVersionGenerator GetGenerator();

		protected Pack GetTestPack()
		{
			return GetTestPack("alert('hello!')");
		}

		protected Pack GetTestPack(string content)
		{
			return GetPack(PackType.JavaScript, "test", content);
		}

		protected Pack GetPack(PackType packType, string packName, string content)
		{
			return GetPack(packType, packName, content, null);
		}

		protected Pack GetPack(PackType packType, string packName, string content, string version)
		{
			var resources = new IResource[] { new ContentResource("content", content) };
			return new Pack(packType, packName, resources, new TestFilter(packType), null, GetGenerator(), version);
		}
	}
}
